/*==============================================================*/
/* DBMS name:      Microsoft SQL Server 2008                    */
/* Created on:     06.08.2010 9:29:07                           */
/*==============================================================*/


if exists (select 1
   from sys.sysreferences r join sys.sysobjects o on (o.id = r.constid and o.type = 'F')
   where r.fkeyid = object_id('BusinessCard') and o.name = 'FK_BCARD_REF_CARDGROU')
alter table BusinessCard
   drop constraint FK_BCARD_REF_CARDGROU
go

if exists (select 1
   from sys.sysreferences r join sys.sysobjects o on (o.id = r.constid and o.type = 'F')
   where r.fkeyid = object_id('BusinessCard') and o.name = 'FK_BCARD_REF_COMP')
alter table BusinessCard
   drop constraint FK_BCARD_REF_COMP
go

if exists (select 1
   from sys.sysreferences r join sys.sysobjects o on (o.id = r.constid and o.type = 'F')
   where r.fkeyid = object_id('BusinessCardToCardFormat') and o.name = 'FK_BCARDFORM_REF_BCARD')
alter table BusinessCardToCardFormat
   drop constraint FK_BCARDFORM_REF_BCARD
go

if exists (select 1
   from sys.sysreferences r join sys.sysobjects o on (o.id = r.constid and o.type = 'F')
   where r.fkeyid = object_id('BusinessCardToCardFormat') and o.name = 'FK_BCARDFORM_REF_FORM')
alter table BusinessCardToCardFormat
   drop constraint FK_BCARDFORM_REF_FORM
go

if exists (select 1
   from sys.sysreferences r join sys.sysobjects o on (o.id = r.constid and o.type = 'F')
   where r.fkeyid = object_id('FinishingPricePolicy') and o.name = 'FK_FINPRPOL_REF_FINSERV')
alter table FinishingPricePolicy
   drop constraint FK_FINPRPOL_REF_FINSERV
go

if exists (select 1
   from sys.sysreferences r join sys.sysobjects o on (o.id = r.constid and o.type = 'F')
   where r.fkeyid = object_id('FinishingPricePolicy') and o.name = 'FK_FINPRPOL_REF_PRINTMED')
alter table FinishingPricePolicy
   drop constraint FK_FINPRPOL_REF_PRINTMED
go

if exists (select 1
   from sys.sysreferences r join sys.sysobjects o on (o.id = r.constid and o.type = 'F')
   where r.fkeyid = object_id('FinishingPricePolicy') and o.name = 'FK_FINPRPOL_REF_PRODTYP')
alter table FinishingPricePolicy
   drop constraint FK_FINPRPOL_REF_PRODTYP
go

if exists (select 1
   from sys.sysreferences r join sys.sysobjects o on (o.id = r.constid and o.type = 'F')
   where r.fkeyid = object_id('FinishingService') and o.name = 'FK_FINSERV_REF_FINSERVTYP')
alter table FinishingService
   drop constraint FK_FINSERV_REF_FINSERVTYP
go

if exists (select 1
   from sys.sysreferences r join sys.sysobjects o on (o.id = r.constid and o.type = 'F')
   where r.fkeyid = object_id('Font') and o.name = 'FK_FONT_REF_LANGUAGE')
alter table Font
   drop constraint FK_FONT_REF_LANGUAGE
go

if exists (select 1
   from sys.sysreferences r join sys.sysobjects o on (o.id = r.constid and o.type = 'F')
   where r.fkeyid = object_id('NewsMessage') and o.name = 'FK_NEWSMESS_REF_LANG')
alter table NewsMessage
   drop constraint FK_NEWSMESS_REF_LANG
go

if exists (select 1
   from sys.sysreferences r join sys.sysobjects o on (o.id = r.constid and o.type = 'F')
   where r.fkeyid = object_id('"Order"') and o.name = 'FK_ORDER_REF_SHIPPING_ADR')
alter table "Order"
   drop constraint FK_ORDER_REF_SHIPPING_ADR
go

if exists (select 1
   from sys.sysreferences r join sys.sysobjects o on (o.id = r.constid and o.type = 'F')
   where r.fkeyid = object_id('OrderHistory') and o.name = 'FK_ORDHIST_REF_ORDER')
alter table OrderHistory
   drop constraint FK_ORDHIST_REF_ORDER
go

if exists (select 1
   from sys.sysreferences r join sys.sysobjects o on (o.id = r.constid and o.type = 'F')
   where r.fkeyid = object_id('OrderHistory') and o.name = 'FK_ORDERHIS_REFERENCE_ASPNET_U')
alter table OrderHistory
   drop constraint FK_ORDERHIS_REFERENCE_ASPNET_U
go

if exists (select 1
   from sys.sysreferences r join sys.sysobjects o on (o.id = r.constid and o.type = 'F')
   where r.fkeyid = object_id('Package') and o.name = 'FK_PACK_REF_ORDER')
alter table Package
   drop constraint FK_PACK_REF_ORDER
go

if exists (select 1
   from sys.sysreferences r join sys.sysobjects o on (o.id = r.constid and o.type = 'F')
   where r.fkeyid = object_id('Package') and o.name = 'FK_PACK_REF_PRICEGRO')
alter table Package
   drop constraint FK_PACK_REF_PRICEGRO
go

if exists (select 1
   from sys.sysreferences r join sys.sysobjects o on (o.id = r.constid and o.type = 'F')
   where r.fkeyid = object_id('Package') and o.name = 'FK_PACK_REF_PRODUCT')
alter table Package
   drop constraint FK_PACK_REF_PRODUCT
go

if exists (select 1
   from sys.sysreferences r join sys.sysobjects o on (o.id = r.constid and o.type = 'F')
   where r.fkeyid = object_id('Package') and o.name = 'FK_PACK_REF_PRTPRICPOL')
alter table Package
   drop constraint FK_PACK_REF_PRTPRICPOL
go

if exists (select 1
   from sys.sysreferences r join sys.sysobjects o on (o.id = r.constid and o.type = 'F')
   where r.fkeyid = object_id('Package') and o.name = 'FK_PACKAGE_REFERENCE_BACKFACE')
alter table Package
   drop constraint FK_PACKAGE_REFERENCE_BACKFACE
go

if exists (select 1
   from sys.sysreferences r join sys.sysobjects o on (o.id = r.constid and o.type = 'F')
   where r.fkeyid = object_id('Package') and o.name = 'FK_PACKAGE_REFERENCE_ASPNET_U')
alter table Package
   drop constraint FK_PACKAGE_REFERENCE_ASPNET_U
go

if exists (select 1
   from sys.sysreferences r join sys.sysobjects o on (o.id = r.constid and o.type = 'F')
   where r.fkeyid = object_id('PackageToFinishingPricePolicy') and o.name = 'FK_PACKFINISH_REF_PACK')
alter table PackageToFinishingPricePolicy
   drop constraint FK_PACKFINISH_REF_PACK
go

if exists (select 1
   from sys.sysreferences r join sys.sysobjects o on (o.id = r.constid and o.type = 'F')
   where r.fkeyid = object_id('PackageToFinishingPricePolicy') and o.name = 'FK_PACKFINPRPOL_REF_FPRPOL')
alter table PackageToFinishingPricePolicy
   drop constraint FK_PACKFINPRPOL_REF_FPRPOL
go

if exists (select 1
   from sys.sysreferences r join sys.sysobjects o on (o.id = r.constid and o.type = 'F')
   where r.fkeyid = object_id('PrintMedia') and o.name = 'FK_PRINTMED_REF_PRINTMET')
alter table PrintMedia
   drop constraint FK_PRINTMED_REF_PRINTMET
go

if exists (select 1
   from sys.sysreferences r join sys.sysobjects o on (o.id = r.constid and o.type = 'F')
   where r.fkeyid = object_id('PrintMedia') and o.name = 'FK_PRTMED_REF_PRTMEDTYP')
alter table PrintMedia
   drop constraint FK_PRTMED_REF_PRTMEDTYP
go

if exists (select 1
   from sys.sysreferences r join sys.sysobjects o on (o.id = r.constid and o.type = 'F')
   where r.fkeyid = object_id('PrintMediaTypeToPrintMethod') and o.name = 'FK_PRMEDTMETH_REF_PRTMEDTY')
alter table PrintMediaTypeToPrintMethod
   drop constraint FK_PRMEDTMETH_REF_PRTMEDTY
go

if exists (select 1
   from sys.sysreferences r join sys.sysobjects o on (o.id = r.constid and o.type = 'F')
   where r.fkeyid = object_id('PrintMediaTypeToPrintMethod') and o.name = 'FK_PRTMEDTOMET_REF_PRTMET')
alter table PrintMediaTypeToPrintMethod
   drop constraint FK_PRTMEDTOMET_REF_PRTMET
go

if exists (select 1
   from sys.sysreferences r join sys.sysobjects o on (o.id = r.constid and o.type = 'F')
   where r.fkeyid = object_id('PrintPricePolicy') and o.name = 'FK_PRPRICP_REF_PRINTMED')
alter table PrintPricePolicy
   drop constraint FK_PRPRICP_REF_PRINTMED
go

if exists (select 1
   from sys.sysreferences r join sys.sysobjects o on (o.id = r.constid and o.type = 'F')
   where r.fkeyid = object_id('PrintPricePolicy') and o.name = 'FK_PRPRICP_REF_PRINTMETH')
alter table PrintPricePolicy
   drop constraint FK_PRPRICP_REF_PRINTMETH
go

if exists (select 1
   from sys.sysreferences r join sys.sysobjects o on (o.id = r.constid and o.type = 'F')
   where r.fkeyid = object_id('PrintPricePolicy') and o.name = 'FK_PRPRICP_REF_PRODTYP')
alter table PrintPricePolicy
   drop constraint FK_PRPRICP_REF_PRODTYP
go

if exists (select 1
   from sys.sysreferences r join sys.sysobjects o on (o.id = r.constid and o.type = 'F')
   where r.fkeyid = object_id('Product') and o.name = 'FK_COMP_REF_PROD_TYP')
alter table Product
   drop constraint FK_COMP_REF_PROD_TYP
go

if exists (select 1
   from sys.sysreferences r join sys.sysobjects o on (o.id = r.constid and o.type = 'F')
   where r.fkeyid = object_id('Product') and o.name = 'FK_PROD_REF_BINDUSTRY')
alter table Product
   drop constraint FK_PROD_REF_BINDUSTRY
go

if exists (select 1
   from sys.sysreferences r join sys.sysobjects o on (o.id = r.constid and o.type = 'F')
   where r.fkeyid = object_id('Product') and o.name = 'FK_PROD_REF_BSTYLE')
alter table Product
   drop constraint FK_PROD_REF_BSTYLE
go

if exists (select 1
   from sys.sysreferences r join sys.sysobjects o on (o.id = r.constid and o.type = 'F')
   where r.fkeyid = object_id('Product') and o.name = 'FK_PROD_REF_COLTHEME')
alter table Product
   drop constraint FK_PROD_REF_COLTHEME
go

if exists (select 1
   from sys.sysreferences r join sys.sysobjects o on (o.id = r.constid and o.type = 'F')
   where r.fkeyid = object_id('Product') and o.name = 'FK_PROD_REF_DEF_DATATEMP')
alter table Product
   drop constraint FK_PROD_REF_DEF_DATATEMP
go

if exists (select 1
   from sys.sysreferences r join sys.sysobjects o on (o.id = r.constid and o.type = 'F')
   where r.fkeyid = object_id('Product') and o.name = 'FK_PROD_REF_DESIGNGR')
alter table Product
   drop constraint FK_PROD_REF_DESIGNGR
go

if exists (select 1
   from sys.sysreferences r join sys.sysobjects o on (o.id = r.constid and o.type = 'F')
   where r.fkeyid = object_id('Product') and o.name = 'FK_PROD_REF_PRINTMED')
alter table Product
   drop constraint FK_PROD_REF_PRINTMED
go

if exists (select 1
   from sys.sysreferences r join sys.sysobjects o on (o.id = r.constid and o.type = 'F')
   where r.fkeyid = object_id('ProductToBackFace') and o.name = 'FK_BCARD_REF_BACKFACE')
alter table ProductToBackFace
   drop constraint FK_BCARD_REF_BACKFACE
go

if exists (select 1
   from sys.sysreferences r join sys.sysobjects o on (o.id = r.constid and o.type = 'F')
   where r.fkeyid = object_id('ProductToBackFace') and o.name = 'FK_PRODBACKFAC_REF_PROD')
alter table ProductToBackFace
   drop constraint FK_PRODBACKFAC_REF_PROD
go

if exists (select 1
   from sys.sysreferences r join sys.sysobjects o on (o.id = r.constid and o.type = 'F')
   where r.fkeyid = object_id('ProductToDataTemplate') and o.name = 'FK_BCDATMP_REF_CDATATMP')
alter table ProductToDataTemplate
   drop constraint FK_BCDATMP_REF_CDATATMP
go

if exists (select 1
   from sys.sysreferences r join sys.sysobjects o on (o.id = r.constid and o.type = 'F')
   where r.fkeyid = object_id('ProductToDataTemplate') and o.name = 'FK_PRDTTEMP_REF_PROD')
alter table ProductToDataTemplate
   drop constraint FK_PRDTTEMP_REF_PROD
go

if exists (select 1
   from sys.sysreferences r join sys.sysobjects o on (o.id = r.constid and o.type = 'F')
   where r.fkeyid = object_id('ProductToPricePolicy') and o.name = 'FK_CMPPRG_REF_COMP')
alter table ProductToPricePolicy
   drop constraint FK_CMPPRG_REF_COMP
go

if exists (select 1
   from sys.sysreferences r join sys.sysobjects o on (o.id = r.constid and o.type = 'F')
   where r.fkeyid = object_id('ProductToPricePolicy') and o.name = 'FK_CMP_REF_PRICEGRO')
alter table ProductToPricePolicy
   drop constraint FK_CMP_REF_PRICEGRO
go

if exists (select 1
   from sys.sysreferences r join sys.sysobjects o on (o.id = r.constid and o.type = 'F')
   where r.fkeyid = object_id('ProductToPrintMedia') and o.name = 'FK_PRODTOMED_REF_PROD')
alter table ProductToPrintMedia
   drop constraint FK_PRODTOMED_REF_PROD
go

if exists (select 1
   from sys.sysreferences r join sys.sysobjects o on (o.id = r.constid and o.type = 'F')
   where r.fkeyid = object_id('ProductToPrintMedia') and o.name = 'FK_PRODUCTT_REFERENCE_PRINTMED')
alter table ProductToPrintMedia
   drop constraint FK_PRODUCTT_REFERENCE_PRINTMED
go

if exists (select 1
   from sys.sysreferences r join sys.sysobjects o on (o.id = r.constid and o.type = 'F')
   where r.fkeyid = object_id('TagToProduct') and o.name = 'FK_TAGTOCOM_REF_PROD')
alter table TagToProduct
   drop constraint FK_TAGTOCOM_REF_PROD
go

if exists (select 1
   from sys.sysreferences r join sys.sysobjects o on (o.id = r.constid and o.type = 'F')
   where r.fkeyid = object_id('TagToProduct') and o.name = 'FK_TAGTOCOM_REF_TAG')
alter table TagToProduct
   drop constraint FK_TAGTOCOM_REF_TAG
go

if exists (select 1
            from  sysobjects
           where  id = object_id('BackFace')
            and   type = 'U')
   drop table BackFace
go

if exists (select 1
            from  sysobjects
           where  id = object_id('BrandLogo')
            and   type = 'U')
   drop table BrandLogo
go

if exists (select 1
            from  sysindexes
           where  id    = object_id('BusinessCard')
            and   name  = 'BCARD_GROUP_IDX'
            and   indid > 0
            and   indid < 255)
   drop index BusinessCard.BCARD_GROUP_IDX
go

if exists (select 1
            from  sysobjects
           where  id = object_id('BusinessCard')
            and   type = 'U')
   drop table BusinessCard
go

if exists (select 1
            from  sysobjects
           where  id = object_id('BusinessCardToCardFormat')
            and   type = 'U')
   drop table BusinessCardToCardFormat
go

if exists (select 1
            from  sysobjects
           where  id = object_id('CardFormat')
            and   type = 'U')
   drop table CardFormat
go

if exists (select 1
            from  sysobjects
           where  id = object_id('CardGroup')
            and   type = 'U')
   drop table CardGroup
go

if exists (select 1
            from  sysindexes
           where  id    = object_id('ColorTheme')
            and   name  = 'COLOR_THEME_RGB_UNIDX'
            and   indid > 0
            and   indid < 255)
   drop index ColorTheme.COLOR_THEME_RGB_UNIDX
go

if exists (select 1
            from  sysobjects
           where  id = object_id('ColorTheme')
            and   type = 'U')
   drop table ColorTheme
go

if exists (select 1
            from  sysobjects
           where  id = object_id('DataTemplate')
            and   type = 'U')
   drop table DataTemplate
go

if exists (select 1
            from  sysobjects
           where  id = object_id('DesignGroup')
            and   type = 'U')
   drop table DesignGroup
go

if exists (select 1
            from  sysindexes
           where  id    = object_id('FinishingPricePolicy')
            and   name  = 'FINPRPOL_ACTV_DATES_IDX'
            and   indid > 0
            and   indid < 255)
   drop index FinishingPricePolicy.FINPRPOL_ACTV_DATES_IDX
go

if exists (select 1
            from  sysindexes
           where  id    = object_id('FinishingPricePolicy')
            and   name  = 'FINPRPOL_MEDI_CODE_IDX'
            and   indid > 0
            and   indid < 255)
   drop index FinishingPricePolicy.FINPRPOL_MEDI_CODE_IDX
go

if exists (select 1
            from  sysindexes
           where  id    = object_id('FinishingPricePolicy')
            and   name  = 'FINPRPOL_SRV_CODE_IDX'
            and   indid > 0
            and   indid < 255)
   drop index FinishingPricePolicy.FINPRPOL_SRV_CODE_IDX
go

if exists (select 1
            from  sysindexes
           where  id    = object_id('FinishingPricePolicy')
            and   name  = 'FINPRPOL_PROD_CODE_IDX'
            and   indid > 0
            and   indid < 255)
   drop index FinishingPricePolicy.FINPRPOL_PROD_CODE_IDX
go

if exists (select 1
            from  sysobjects
           where  id = object_id('FinishingPricePolicy')
            and   type = 'U')
   drop table FinishingPricePolicy
go

if exists (select 1
            from  sysindexes
           where  id    = object_id('FinishingService')
            and   name  = 'FINSRV_SRV_TYP_IDX'
            and   indid > 0
            and   indid < 255)
   drop index FinishingService.FINSRV_SRV_TYP_IDX
go

if exists (select 1
            from  sysobjects
           where  id = object_id('FinishingService')
            and   type = 'U')
   drop table FinishingService
go

if exists (select 1
            from  sysobjects
           where  id = object_id('FinishingServiceType')
            and   type = 'U')
   drop table FinishingServiceType
go

if exists (select 1
            from  sysindexes
           where  id    = object_id('Font')
            and   name  = 'FONT_FILENAME_UNQ_IDX'
            and   indid > 0
            and   indid < 255)
   drop index Font.FONT_FILENAME_UNQ_IDX
go

if exists (select 1
            from  sysobjects
           where  id = object_id('Font')
            and   type = 'U')
   drop table Font
go

if exists (select 1
            from  sysobjects
           where  id = object_id('Industry')
            and   type = 'U')
   drop table Industry
go

if exists (select 1
            from  sysobjects
           where  id = object_id('Language')
            and   type = 'U')
   drop table Language
go

if exists (select 1
            from  sysobjects
           where  id = object_id('NewsMessage')
            and   type = 'U')
   drop table NewsMessage
go

if exists (select 1
            from  sysindexes
           where  id    = object_id('"Order"')
            and   name  = 'ORDER_DATE_IDX'
            and   indid > 0
            and   indid < 255)
   drop index "Order".ORDER_DATE_IDX
go

if exists (select 1
            from  sysindexes
           where  id    = object_id('"Order"')
            and   name  = 'ORDER_SHIPPING_IDX'
            and   indid > 0
            and   indid < 255)
   drop index "Order".ORDER_SHIPPING_IDX
go

if exists (select 1
            from  sysindexes
           where  id    = object_id('"Order"')
            and   name  = 'ORDER_STATUS_IDX'
            and   indid > 0
            and   indid < 255)
   drop index "Order".ORDER_STATUS_IDX
go

if exists (select 1
            from  sysobjects
           where  id = object_id('"Order"')
            and   type = 'U')
   drop table "Order"
go

if exists (select 1
            from  sysindexes
           where  id    = object_id('OrderHistory')
            and   name  = 'ORDER_HIST_STSDATE_IDX'
            and   indid > 0
            and   indid < 255)
   drop index OrderHistory.ORDER_HIST_STSDATE_IDX
go

if exists (select 1
            from  sysindexes
           where  id    = object_id('OrderHistory')
            and   name  = 'ORDER_HIST_ORDER_IDX'
            and   indid > 0
            and   indid < 255)
   drop index OrderHistory.ORDER_HIST_ORDER_IDX
go

if exists (select 1
            from  sysobjects
           where  id = object_id('OrderHistory')
            and   type = 'U')
   drop table OrderHistory
go

if exists (select 1
            from  sysindexes
           where  id    = object_id('Package')
            and   name  = 'PACK_BACKFC_IDX'
            and   indid > 0
            and   indid < 255)
   drop index Package.PACK_BACKFC_IDX
go

if exists (select 1
            from  sysindexes
           where  id    = object_id('Package')
            and   name  = 'PACK_PRT_PRICPOL_IDX'
            and   indid > 0
            and   indid < 255)
   drop index Package.PACK_PRT_PRICPOL_IDX
go

if exists (select 1
            from  sysindexes
           where  id    = object_id('Package')
            and   name  = 'PACK_PRICE_GROP_IDX'
            and   indid > 0
            and   indid < 255)
   drop index Package.PACK_PRICE_GROP_IDX
go

if exists (select 1
            from  sysindexes
           where  id    = object_id('Package')
            and   name  = 'PACK_PROD_IDX'
            and   indid > 0
            and   indid < 255)
   drop index Package.PACK_PROD_IDX
go

if exists (select 1
            from  sysindexes
           where  id    = object_id('Package')
            and   name  = 'PACKAGE_USER_IDX'
            and   indid > 0
            and   indid < 255)
   drop index Package.PACKAGE_USER_IDX
go

if exists (select 1
            from  sysindexes
           where  id    = object_id('Package')
            and   name  = 'PACKAGE_ORDER_IDX'
            and   indid > 0
            and   indid < 255)
   drop index Package.PACKAGE_ORDER_IDX
go

if exists (select 1
            from  sysobjects
           where  id = object_id('Package')
            and   type = 'U')
   drop table Package
go

if exists (select 1
            from  sysobjects
           where  id = object_id('PackageToFinishingPricePolicy')
            and   type = 'U')
   drop table PackageToFinishingPricePolicy
go

if exists (select 1
            from  sysindexes
           where  id    = object_id('PricePolicy')
            and   name  = 'PRC_GRP_ACTIVE_IDX'
            and   indid > 0
            and   indid < 255)
   drop index PricePolicy.PRC_GRP_ACTIVE_IDX
go

if exists (select 1
            from  sysobjects
           where  id = object_id('PricePolicy')
            and   type = 'U')
   drop table PricePolicy
go

if exists (select 1
            from  sysindexes
           where  id    = object_id('PrintMedia')
            and   name  = 'PRINT_MED_MEDIA_TYP_IDX'
            and   indid > 0
            and   indid < 255)
   drop index PrintMedia.PRINT_MED_MEDIA_TYP_IDX
go

if exists (select 1
            from  sysindexes
           where  id    = object_id('PrintMedia')
            and   name  = 'PRINT_MED_DEFMETHOD_IDX'
            and   indid > 0
            and   indid < 255)
   drop index PrintMedia.PRINT_MED_DEFMETHOD_IDX
go

if exists (select 1
            from  sysobjects
           where  id = object_id('PrintMedia')
            and   type = 'U')
   drop table PrintMedia
go

if exists (select 1
            from  sysobjects
           where  id = object_id('PrintMediaType')
            and   type = 'U')
   drop table PrintMediaType
go

if exists (select 1
            from  sysobjects
           where  id = object_id('PrintMediaTypeToPrintMethod')
            and   type = 'U')
   drop table PrintMediaTypeToPrintMethod
go

if exists (select 1
            from  sysobjects
           where  id = object_id('PrintMethod')
            and   type = 'U')
   drop table PrintMethod
go

if exists (select 1
            from  sysindexes
           where  id    = object_id('PrintPricePolicy')
            and   name  = 'PRNTPOL_ACTV_DATES_IDX'
            and   indid > 0
            and   indid < 255)
   drop index PrintPricePolicy.PRNTPOL_ACTV_DATES_IDX
go

if exists (select 1
            from  sysindexes
           where  id    = object_id('PrintPricePolicy')
            and   name  = 'PRNTPOL_PROD_CODE_IDX'
            and   indid > 0
            and   indid < 255)
   drop index PrintPricePolicy.PRNTPOL_PROD_CODE_IDX
go

if exists (select 1
            from  sysindexes
           where  id    = object_id('PrintPricePolicy')
            and   name  = 'PRNTPOL_METH_CODE_IDX'
            and   indid > 0
            and   indid < 255)
   drop index PrintPricePolicy.PRNTPOL_METH_CODE_IDX
go

if exists (select 1
            from  sysindexes
           where  id    = object_id('PrintPricePolicy')
            and   name  = 'PRNTPOL_MEDI_CODE_IDX'
            and   indid > 0
            and   indid < 255)
   drop index PrintPricePolicy.PRNTPOL_MEDI_CODE_IDX
go

if exists (select 1
            from  sysobjects
           where  id = object_id('PrintPricePolicy')
            and   type = 'U')
   drop table PrintPricePolicy
go

if exists (select 1
            from  sysindexes
           where  id    = object_id('Product')
            and   name  = 'PRODUCT_CREAT_DT_IDX'
            and   indid > 0
            and   indid < 255)
   drop index Product.PRODUCT_CREAT_DT_IDX
go

if exists (select 1
            from  sysindexes
           where  id    = object_id('Product')
            and   name  = 'PRODUCT_DEF_DTTMPL_IDX'
            and   indid > 0
            and   indid < 255)
   drop index Product.PRODUCT_DEF_DTTMPL_IDX
go

if exists (select 1
            from  sysindexes
           where  id    = object_id('Product')
            and   name  = 'PRODUCT_COL_THEME_IDX'
            and   indid > 0
            and   indid < 255)
   drop index Product.PRODUCT_COL_THEME_IDX
go

if exists (select 1
            from  sysindexes
           where  id    = object_id('Product')
            and   name  = 'PRODUCT_DES_GRP_IDX'
            and   indid > 0
            and   indid < 255)
   drop index Product.PRODUCT_DES_GRP_IDX
go

if exists (select 1
            from  sysindexes
           where  id    = object_id('Product')
            and   name  = 'PRODUCT_DEF_PRMEDIA_IDX'
            and   indid > 0
            and   indid < 255)
   drop index Product.PRODUCT_DEF_PRMEDIA_IDX
go

if exists (select 1
            from  sysindexes
           where  id    = object_id('Product')
            and   name  = 'PRODUCT_STYLE_IDX'
            and   indid > 0
            and   indid < 255)
   drop index Product.PRODUCT_STYLE_IDX
go

if exists (select 1
            from  sysindexes
           where  id    = object_id('Product')
            and   name  = 'PRODUCT_INDUSTRY_IDX'
            and   indid > 0
            and   indid < 255)
   drop index Product.PRODUCT_INDUSTRY_IDX
go

if exists (select 1
            from  sysindexes
           where  id    = object_id('Product')
            and   name  = 'PROD_PROD_TYP_IDX'
            and   indid > 0
            and   indid < 255)
   drop index Product.PROD_PROD_TYP_IDX
go

if exists (select 1
            from  sysobjects
           where  id = object_id('Product')
            and   type = 'U')
   drop table Product
go

if exists (select 1
            from  sysobjects
           where  id = object_id('ProductToBackFace')
            and   type = 'U')
   drop table ProductToBackFace
go

if exists (select 1
            from  sysobjects
           where  id = object_id('ProductToDataTemplate')
            and   type = 'U')
   drop table ProductToDataTemplate
go

if exists (select 1
            from  sysobjects
           where  id = object_id('ProductToPricePolicy')
            and   type = 'U')
   drop table ProductToPricePolicy
go

if exists (select 1
            from  sysobjects
           where  id = object_id('ProductToPrintMedia')
            and   type = 'U')
   drop table ProductToPrintMedia
go

if exists (select 1
            from  sysobjects
           where  id = object_id('ProductType')
            and   type = 'U')
   drop table ProductType
go

if exists (select 1
            from  sysobjects
           where  id = object_id('SchemaVersion')
            and   type = 'U')
   drop table SchemaVersion
go

if exists (select 1
            from  sysindexes
           where  id    = object_id('ShippingAddress')
            and   name  = 'SHIPP_ADDR_EMAIL_IDX'
            and   indid > 0
            and   indid < 255)
   drop index ShippingAddress.SHIPP_ADDR_EMAIL_IDX
go

if exists (select 1
            from  sysindexes
           where  id    = object_id('ShippingAddress')
            and   name  = 'SHIPP_ADDR_MOB_IDX'
            and   indid > 0
            and   indid < 255)
   drop index ShippingAddress.SHIPP_ADDR_MOB_IDX
go

if exists (select 1
            from  sysindexes
           where  id    = object_id('ShippingAddress')
            and   name  = 'SHIPP_ADDR_TEL_IDX'
            and   indid > 0
            and   indid < 255)
   drop index ShippingAddress.SHIPP_ADDR_TEL_IDX
go

if exists (select 1
            from  sysobjects
           where  id = object_id('ShippingAddress')
            and   type = 'U')
   drop table ShippingAddress
go

if exists (select 1
            from  sysobjects
           where  id = object_id('Style')
            and   type = 'U')
   drop table Style
go

if exists (select 1
            from  sysobjects
           where  id = object_id('Tag')
            and   type = 'U')
   drop table Tag
go

if exists (select 1
            from  sysobjects
           where  id = object_id('TagToProduct')
            and   type = 'U')
   drop table TagToProduct
go

if exists (select 1
            from  sysobjects
           where  id = object_id('aspnet_Users')
            and   type = 'U')
   drop table aspnet_Users
go

/*==============================================================*/
/* Table: BackFace                                              */
/*==============================================================*/
create table BackFace (
   BackFaceId           bigint               identity,
   ImageDataPath        varchar(255)         not null,
   NameEn               nvarchar(100)        not null,
   NameRu               nvarchar(100)        not null,
   NameAm               nvarchar(100)        not null,
   constraint PK_BACKFACE primary key (BackFaceId)
)
go

/*==============================================================*/
/* Table: BrandLogo                                             */
/*==============================================================*/
create table BrandLogo (
   BrandLogoId          int                  identity,
   NameEn               nvarchar(100)        not null,
   NameRu               nvarchar(100)        not null,
   NameAm               nvarchar(100)        not null,
   CreateDate           datetime             not null,
   constraint PK_BRANDLOGO primary key (BrandLogoId)
)
go

/*==============================================================*/
/* Table: BusinessCard                                          */
/*==============================================================*/
create table BusinessCard (
   BusinessCardId       bigint               not null,
   Type                 char(4)              not null,
   CardGroupCode        char(4)              not null,
   ImageDataPath        varchar(255)         not null,
   constraint PK_BUSINESSCARD primary key (BusinessCardId)
)
go

/*==============================================================*/
/* Index: BCARD_GROUP_IDX                                       */
/*==============================================================*/
create index BCARD_GROUP_IDX on BusinessCard (
CardGroupCode ASC
)
go

/*==============================================================*/
/* Table: BusinessCardToCardFormat                              */
/*==============================================================*/
create table BusinessCardToCardFormat (
   BusinessCardId       bigint               not null,
   FormatCode           char(4)              not null,
   constraint PK_BUSINESSCARDTOCARDFORMAT primary key (BusinessCardId, FormatCode)
)
go

/*==============================================================*/
/* Table: CardFormat                                            */
/*==============================================================*/
create table CardFormat (
   FormatCode           char(4)              not null,
   NameEn               nvarchar(100)        not null,
   NameRu               nvarchar(100)        not null,
   NameAm               nvarchar(100)        not null,
   constraint PK_CARDFORMAT primary key (FormatCode)
)
go

/*==============================================================*/
/* Table: CardGroup                                             */
/*==============================================================*/
create table CardGroup (
   CardGroupCode        char(4)              not null,
   NameEn               nvarchar(100)        not null,
   NameRu               nvarchar(100)        not null,
   NameAm               nvarchar(100)        not null,
   constraint PK_CARDGROUP primary key (CardGroupCode)
)
go

/*==============================================================*/
/* Table: ColorTheme                                            */
/*==============================================================*/
create table ColorTheme (
   ColorThemeId         int                  identity,
   RGBHex               char(6)              not null,
   NameEn               nvarchar(100)        not null,
   NameRu               nvarchar(100)        not null,
   NameAm               nvarchar(100)        not null,
   constraint PK_COLORTHEME primary key (ColorThemeId)
)
go

/*==============================================================*/
/* Index: COLOR_THEME_RGB_UNIDX                                 */
/*==============================================================*/
create unique index COLOR_THEME_RGB_UNIDX on ColorTheme (
RGBHex ASC
)
go

/*==============================================================*/
/* Table: DataTemplate                                          */
/*==============================================================*/
create table DataTemplate (
   DataTemplateId       int                  identity,
   TemplateXML          nvarchar(MAX)        not null,
   NameEn               nvarchar(100)        not null,
   NameRu               nvarchar(100)        not null,
   NameAm               nvarchar(100)        not null,
   CreateDate           datetime             not null,
   constraint PK_DATATEMPLATE primary key (DataTemplateId)
)
go

/*==============================================================*/
/* Table: DesignGroup                                           */
/*==============================================================*/
create table DesignGroup (
   DesignGroupId        bigint               identity,
   NameEn               nvarchar(100)        not null,
   NameRu               nvarchar(100)        not null,
   NameAm               nvarchar(100)        not null,
   constraint PK_DESIGNGROUP primary key (DesignGroupId)
)
go

/*==============================================================*/
/* Table: FinishingPricePolicy                                  */
/*==============================================================*/
create table FinishingPricePolicy (
   FinishingPricePolicyId bigint               identity,
   ProductCode          char(5)              not null,
   FinishingServiceCode char(4)              not null,
   PrintMediaCode       char(6)              not null,
   Price                money                not null,
   Quantity             int                  not null,
   ActiveFrom           datetime             not null,
   ActiveTo             datetime             null,
   constraint PK_FINISHINGPRICEPOLICY primary key (FinishingPricePolicyId)
)
go

/*==============================================================*/
/* Index: FINPRPOL_PROD_CODE_IDX                                */
/*==============================================================*/
create index FINPRPOL_PROD_CODE_IDX on FinishingPricePolicy (
ProductCode ASC
)
go

/*==============================================================*/
/* Index: FINPRPOL_SRV_CODE_IDX                                 */
/*==============================================================*/
create index FINPRPOL_SRV_CODE_IDX on FinishingPricePolicy (
FinishingServiceCode ASC
)
go

/*==============================================================*/
/* Index: FINPRPOL_MEDI_CODE_IDX                                */
/*==============================================================*/
create index FINPRPOL_MEDI_CODE_IDX on FinishingPricePolicy (
PrintMediaCode ASC
)
go

/*==============================================================*/
/* Index: FINPRPOL_ACTV_DATES_IDX                               */
/*==============================================================*/
create index FINPRPOL_ACTV_DATES_IDX on FinishingPricePolicy (
ActiveFrom ASC,
ActiveTo ASC
)
go

/*==============================================================*/
/* Table: FinishingService                                      */
/*==============================================================*/
create table FinishingService (
   FinishingServiceCode char(4)              not null,
   FinishingServiceType char(4)              not null,
   AvailableFrom        datetime             null,
   DescriptionEn        nvarchar(2000)       not null,
   DescriptionRu        nvarchar(2000)       not null,
   DescriptionAm        nvarchar(2000)       not null,
   NameEn               nvarchar(100)        not null,
   NameRu               nvarchar(100)        not null,
   NameAm               nvarchar(100)        not null,
   CreateDate           datetime             not null,
   constraint PK_FINISHINGSERVICE primary key (FinishingServiceCode)
)
go

/*==============================================================*/
/* Index: FINSRV_SRV_TYP_IDX                                    */
/*==============================================================*/
create index FINSRV_SRV_TYP_IDX on FinishingService (
FinishingServiceType ASC
)
go

/*==============================================================*/
/* Table: FinishingServiceType                                  */
/*==============================================================*/
create table FinishingServiceType (
   FinishingServiceType char(4)              not null,
   Comment              varchar(255)         null,
   constraint PK_FINISHINGSERVICETYPE primary key (FinishingServiceType)
)
go

/*==============================================================*/
/* Table: Font                                                  */
/*==============================================================*/
create table Font (
   FontId               int                  identity,
   Name                 varchar(255)         not null,
   FileName             varchar(100)         not null,
   IsUnicode            bit                  not null,
   LanguageCode         char(2)              null,
   Style                char(2)              null,
   CreateDate           datetime             not null,
   constraint PK_FONT primary key (FontId)
)
go

/*==============================================================*/
/* Index: FONT_FILENAME_UNQ_IDX                                 */
/*==============================================================*/
create unique index FONT_FILENAME_UNQ_IDX on Font (
FileName ASC
)
go

/*==============================================================*/
/* Table: Industry                                              */
/*==============================================================*/
create table Industry (
   IndustryId           int                  identity,
   NameEn               nvarchar(100)        not null,
   NameRu               nvarchar(100)        not null,
   NameAm               nvarchar(100)        not null,
   constraint PK_INDUSTRY primary key (IndustryId)
)
go

/*==============================================================*/
/* Table: Language                                              */
/*==============================================================*/
create table Language (
   Code                 char(2)              not null,
   Name                 nvarchar(50)         not null,
   FlagImagePath        varchar(255)         not null,
   constraint PK_LANGUAGE primary key (Code)
)
go

/*==============================================================*/
/* Table: NewsMessage                                           */
/*==============================================================*/
create table NewsMessage (
   NewsId               bigint               not null,
   TextHtml             nvarchar(MAX)        not null,
   LangCode             char(2)              not null,
   Subject              nvarchar(200)        not null,
   IsApproved           bit                  not null,
   CreateDate           datetime             not null,
   constraint PK_NEWSMESSAGE primary key (NewsId)
)
go

/*==============================================================*/
/* Table: "Order"                                               */
/*==============================================================*/
create table "Order" (
   OrderId              bigint               identity,
   ShippingAddressId    bigint               not null,
   Status               char(3)              not null,
   OrderDate            datetime             not null,
   constraint PK_ORDER primary key (OrderId)
)
go

/*==============================================================*/
/* Index: ORDER_STATUS_IDX                                      */
/*==============================================================*/
create index ORDER_STATUS_IDX on "Order" (
Status ASC
)
go

/*==============================================================*/
/* Index: ORDER_SHIPPING_IDX                                    */
/*==============================================================*/
create index ORDER_SHIPPING_IDX on "Order" (
ShippingAddressId ASC
)
go

/*==============================================================*/
/* Index: ORDER_DATE_IDX                                        */
/*==============================================================*/
create index ORDER_DATE_IDX on "Order" (
OrderDate DESC
)
go

/*==============================================================*/
/* Table: OrderHistory                                          */
/*==============================================================*/
create table OrderHistory (
   OrderHistoryId       bigint               identity,
   OrderId              bigint               not null,
   ModifierUserId       uniqueidentifier     not null,
   Status               char(3)              not null,
   StatusDate           datetime             not null,
   constraint PK_ORDERHISTORY primary key (OrderHistoryId)
)
go

/*==============================================================*/
/* Index: ORDER_HIST_ORDER_IDX                                  */
/*==============================================================*/
create index ORDER_HIST_ORDER_IDX on OrderHistory (
OrderId ASC
)
go

/*==============================================================*/
/* Index: ORDER_HIST_STSDATE_IDX                                */
/*==============================================================*/
create index ORDER_HIST_STSDATE_IDX on OrderHistory (
StatusDate DESC
)
go

/*==============================================================*/
/* Table: Package                                               */
/*==============================================================*/
create table Package (
   PackageId            bigint               identity,
   OrderId              bigint               null,
   ProductId            bigint               not null,
   PricePolicyId        bigint               not null,
   PrintPricePolicyId   bigint               not null,
   BackFaceId           bigint               null,
   UserId               uniqueidentifier     not null,
   PrintReadyFilePath   varchar(255)         null,
   InfoDataXML          nvarchar(MAX)        null,
   Quantity             int                  not null,
   TotalPrice           money                not null,
   CreateDate           datetime             not null,
   constraint PK_PACKAGE primary key (PackageId)
)
go

/*==============================================================*/
/* Index: PACKAGE_ORDER_IDX                                     */
/*==============================================================*/
create index PACKAGE_ORDER_IDX on Package (
OrderId ASC
)
go

/*==============================================================*/
/* Index: PACKAGE_USER_IDX                                      */
/*==============================================================*/
create index PACKAGE_USER_IDX on Package (
UserId ASC
)
go

/*==============================================================*/
/* Index: PACK_PROD_IDX                                         */
/*==============================================================*/
create index PACK_PROD_IDX on Package (
ProductId ASC
)
go

/*==============================================================*/
/* Index: PACK_PRICE_GROP_IDX                                   */
/*==============================================================*/
create index PACK_PRICE_GROP_IDX on Package (
PricePolicyId ASC
)
go

/*==============================================================*/
/* Index: PACK_PRT_PRICPOL_IDX                                  */
/*==============================================================*/
create index PACK_PRT_PRICPOL_IDX on Package (
PrintPricePolicyId ASC
)
go

/*==============================================================*/
/* Index: PACK_BACKFC_IDX                                       */
/*==============================================================*/
create index PACK_BACKFC_IDX on Package (
BackFaceId ASC
)
go

/*==============================================================*/
/* Table: PackageToFinishingPricePolicy                         */
/*==============================================================*/
create table PackageToFinishingPricePolicy (
   PackageId            bigint               not null,
   FinishingPricePolicyId bigint               not null,
   constraint PK_PACKAGETOFINISHINGPRICEPOLI primary key (PackageId, FinishingPricePolicyId)
)
go

/*==============================================================*/
/* Table: PricePolicy                                           */
/*==============================================================*/
create table PricePolicy (
   PricePolicyId        bigint               identity,
   Quantity             int                  not null,
   Price                money                not null,
   ActiveFrom           datetime             not null,
   ActiveTo             datetime             null,
   NameEn               nvarchar(100)        not null,
   NameRu               nvarchar(100)        not null,
   NameAm               nvarchar(100)        not null,
   CreateDate           datetime             not null,
   constraint PK_PRICEPOLICY primary key (PricePolicyId)
)
go

/*==============================================================*/
/* Index: PRC_GRP_ACTIVE_IDX                                    */
/*==============================================================*/
create index PRC_GRP_ACTIVE_IDX on PricePolicy (
ActiveFrom DESC,
ActiveTo DESC
)
go

/*==============================================================*/
/* Table: PrintMedia                                            */
/*==============================================================*/
create table PrintMedia (
   MediaCode            char(6)              not null,
   DefaultPrintMethodCode char(6)              not null,
   MediaTypeCode        char(4)              not null,
   Name                 nvarchar(255)        not null,
   WeightGr             int                  null,
   DescriptionEn        nvarchar(2000)       not null,
   DescriptionRu        nvarchar(2000)       not null,
   DescriptionAm        nvarchar(2000)       not null,
   NameEn               nvarchar(100)        not null,
   NameRu               nvarchar(100)        not null,
   NameAm               nvarchar(100)        not null,
   Status               char(2)              null,
   AvailableFrom        datetime             null,
   CreateDate           datetime             not null,
   constraint PK_PRINTMEDIA primary key (MediaCode)
)
go

/*==============================================================*/
/* Index: PRINT_MED_DEFMETHOD_IDX                               */
/*==============================================================*/
create index PRINT_MED_DEFMETHOD_IDX on PrintMedia (
DefaultPrintMethodCode ASC
)
go

/*==============================================================*/
/* Index: PRINT_MED_MEDIA_TYP_IDX                               */
/*==============================================================*/
create index PRINT_MED_MEDIA_TYP_IDX on PrintMedia (
MediaTypeCode ASC
)
go

/*==============================================================*/
/* Table: PrintMediaType                                        */
/*==============================================================*/
create table PrintMediaType (
   MediaTypeCode        char(4)              not null,
   DescriptionEn        nvarchar(2000)       not null,
   DescriptionRu        nvarchar(2000)       not null,
   DescriptionAm        nvarchar(2000)       not null,
   NameEn               nvarchar(100)        not null,
   NameRu               nvarchar(100)        not null,
   NameAm               nvarchar(100)        not null,
   CreateDate           datetime             not null,
   constraint PK_PRINTMEDIATYPE primary key (MediaTypeCode)
)
go

/*==============================================================*/
/* Table: PrintMediaTypeToPrintMethod                           */
/*==============================================================*/
create table PrintMediaTypeToPrintMethod (
   MethodCode           char(6)              not null,
   MediaTypeCode        char(4)              not null,
   constraint PK_PRINTMEDIATYPETOPRINTMETHOD primary key (MethodCode, MediaTypeCode)
)
go

/*==============================================================*/
/* Table: PrintMethod                                           */
/*==============================================================*/
create table PrintMethod (
   MethodCode           char(6)              not null,
   Duration             int                  not null,
   BothSide             bit                  not null,
   DescriptionEn        nvarchar(2000)       not null,
   DescriptionRu        nvarchar(2000)       not null,
   DescriptionAm        nvarchar(2000)       not null,
   NameEn               nvarchar(100)        not null,
   NameRu               nvarchar(100)        not null,
   NameAm               nvarchar(100)        not null,
   AvailableFrom        datetime             null,
   CreateDate           datetime             not null,
   constraint PK_PRINTMETHOD primary key (MethodCode)
)
go

/*==============================================================*/
/* Table: PrintPricePolicy                                      */
/*==============================================================*/
create table PrintPricePolicy (
   PrintPricePolicyId   bigint               identity,
   PrintMediaCode       char(6)              not null,
   PrintMethodCode      char(6)              not null,
   ProductCode          char(5)              not null,
   Price                money                not null,
   Quantity             int                  not null,
   ActiveFrom           datetime             not null,
   ActiveTo             datetime             null,
   constraint PK_PRINTPRICEPOLICY primary key (PrintPricePolicyId)
)
go

/*==============================================================*/
/* Index: PRNTPOL_MEDI_CODE_IDX                                 */
/*==============================================================*/
create index PRNTPOL_MEDI_CODE_IDX on PrintPricePolicy (
PrintMediaCode ASC
)
go

/*==============================================================*/
/* Index: PRNTPOL_METH_CODE_IDX                                 */
/*==============================================================*/
create index PRNTPOL_METH_CODE_IDX on PrintPricePolicy (
PrintMethodCode ASC
)
go

/*==============================================================*/
/* Index: PRNTPOL_PROD_CODE_IDX                                 */
/*==============================================================*/
create index PRNTPOL_PROD_CODE_IDX on PrintPricePolicy (
ProductCode ASC
)
go

/*==============================================================*/
/* Index: PRNTPOL_ACTV_DATES_IDX                                */
/*==============================================================*/
create index PRNTPOL_ACTV_DATES_IDX on PrintPricePolicy (
ActiveFrom ASC,
ActiveTo ASC
)
go

/*==============================================================*/
/* Table: Product                                               */
/*==============================================================*/
create table Product (
   ProductId            bigint               identity,
   ProductCode          char(5)              not null,
   StyleId              int                  not null,
   IndustryId           int                  not null,
   DesignGroupId        bigint               not null,
   ColorThemeId         int                  not null,
   DefaultPrintMedia    char(6)              not null,
   DefaultDataTemplateId int                  not null,
   NameEn               nvarchar(100)        not null,
   NameRu               nvarchar(100)        not null,
   NameAm               nvarchar(100)        not null,
   Status               char(2)              not null,
   CreateDate           datetime             not null,
   constraint PK_PRODUCT primary key (ProductId)
)
go

/*==============================================================*/
/* Index: PROD_PROD_TYP_IDX                                     */
/*==============================================================*/
create index PROD_PROD_TYP_IDX on Product (
ProductCode ASC
)
go

/*==============================================================*/
/* Index: PRODUCT_INDUSTRY_IDX                                  */
/*==============================================================*/
create index PRODUCT_INDUSTRY_IDX on Product (
IndustryId ASC
)
go

/*==============================================================*/
/* Index: PRODUCT_STYLE_IDX                                     */
/*==============================================================*/
create index PRODUCT_STYLE_IDX on Product (
StyleId ASC
)
go

/*==============================================================*/
/* Index: PRODUCT_DEF_PRMEDIA_IDX                               */
/*==============================================================*/
create index PRODUCT_DEF_PRMEDIA_IDX on Product (
DefaultPrintMedia ASC
)
go

/*==============================================================*/
/* Index: PRODUCT_DES_GRP_IDX                                   */
/*==============================================================*/
create index PRODUCT_DES_GRP_IDX on Product (
DesignGroupId ASC
)
go

/*==============================================================*/
/* Index: PRODUCT_COL_THEME_IDX                                 */
/*==============================================================*/
create index PRODUCT_COL_THEME_IDX on Product (
ColorThemeId ASC
)
go

/*==============================================================*/
/* Index: PRODUCT_DEF_DTTMPL_IDX                                */
/*==============================================================*/
create index PRODUCT_DEF_DTTMPL_IDX on Product (
DefaultDataTemplateId ASC
)
go

/*==============================================================*/
/* Index: PRODUCT_CREAT_DT_IDX                                  */
/*==============================================================*/
create index PRODUCT_CREAT_DT_IDX on Product (
CreateDate ASC
)
go

/*==============================================================*/
/* Table: ProductToBackFace                                     */
/*==============================================================*/
create table ProductToBackFace (
   ProductId            bigint               not null,
   BackFaceId           bigint               not null,
   constraint PK_PRODUCTTOBACKFACE primary key (ProductId, BackFaceId)
)
go

/*==============================================================*/
/* Table: ProductToDataTemplate                                 */
/*==============================================================*/
create table ProductToDataTemplate (
   DataTemplateId       int                  not null,
   ProductId            bigint               not null,
   constraint PK_PRODUCTTODATATEMPLATE primary key (DataTemplateId, ProductId)
)
go

/*==============================================================*/
/* Table: ProductToPricePolicy                                  */
/*==============================================================*/
create table ProductToPricePolicy (
   PricePolicyId        bigint               not null,
   ProductId            bigint               not null,
   constraint PK_PRODUCTTOPRICEPOLICY primary key (PricePolicyId, ProductId)
)
go

/*==============================================================*/
/* Table: ProductToPrintMedia                                   */
/*==============================================================*/
create table ProductToPrintMedia (
   ProductId            bigint               not null,
   MediaCode            char(6)              not null,
   constraint PK_PRODUCTTOPRINTMEDIA primary key (ProductId, MediaCode)
)
go

/*==============================================================*/
/* Table: ProductType                                           */
/*==============================================================*/
create table ProductType (
   ProductCode          char(5)              not null,
   NameEn               nvarchar(100)        not null,
   NameRu               nvarchar(100)        not null,
   NameAm               nvarchar(100)        not null,
   constraint PK_PRODUCTTYPE primary key (ProductCode)
)
go

/*==============================================================*/
/* Table: SchemaVersion                                         */
/*==============================================================*/
create table SchemaVersion (
   SchemaVersionId      int                  identity,
   VersionNumber        smallint             not null,
   IsCurrent            bit                  not null,
   CreateDate           datetime             not null,
   constraint PK_SCHEMAVERSION primary key (SchemaVersionId)
)
go

/*==============================================================*/
/* Table: ShippingAddress                                       */
/*==============================================================*/
create table ShippingAddress (
   ShippingAddressId    bigint               identity,
   Address              nvarchar(500)        not null,
   PostalCode           varchar(20)          null,
   Tel                  varchar(100)         not null,
   Mobile               varchar(100)         null,
   Email                varchar(255)         null,
   constraint PK_SHIPPINGADDRESS primary key (ShippingAddressId)
)
go

/*==============================================================*/
/* Index: SHIPP_ADDR_TEL_IDX                                    */
/*==============================================================*/
create index SHIPP_ADDR_TEL_IDX on ShippingAddress (
Tel ASC
)
go

/*==============================================================*/
/* Index: SHIPP_ADDR_MOB_IDX                                    */
/*==============================================================*/
create index SHIPP_ADDR_MOB_IDX on ShippingAddress (
Mobile ASC
)
go

/*==============================================================*/
/* Index: SHIPP_ADDR_EMAIL_IDX                                  */
/*==============================================================*/
create index SHIPP_ADDR_EMAIL_IDX on ShippingAddress (
Email ASC
)
go

/*==============================================================*/
/* Table: Style                                                 */
/*==============================================================*/
create table Style (
   StyleId              int                  identity,
   NameEn               nvarchar(100)        not null,
   NameRu               nvarchar(100)        not null,
   NameAm               nvarchar(100)        not null,
   constraint PK_STYLE primary key (StyleId)
)
go

/*==============================================================*/
/* Table: Tag                                                   */
/*==============================================================*/
create table Tag (
   TagId                bigint               identity,
   NameEn               nvarchar(100)        not null,
   NameRu               nvarchar(100)        not null,
   NameAm               nvarchar(100)        not null,
   constraint PK_TAG primary key (TagId)
)
go

/*==============================================================*/
/* Table: TagToProduct                                          */
/*==============================================================*/
create table TagToProduct (
   TagId                bigint               not null,
   ProductId            bigint               not null,
   constraint PK_TAGTOPRODUCT primary key (TagId, ProductId)
)
go

/*==============================================================*/
/* Table: aspnet_Users                                          */
/*==============================================================*/
create table aspnet_Users (
   UserId               uniqueidentifier     not null,
   constraint PK_ASPNET_USERS primary key (UserId)
)
go

alter table BusinessCard
   add constraint FK_BCARD_REF_CARDGROU foreign key (CardGroupCode)
      references CardGroup (CardGroupCode)
go

alter table BusinessCard
   add constraint FK_BCARD_REF_COMP foreign key (BusinessCardId)
      references Product (ProductId)
         on delete cascade
go

alter table BusinessCardToCardFormat
   add constraint FK_BCARDFORM_REF_BCARD foreign key (BusinessCardId)
      references BusinessCard (BusinessCardId)
         on delete cascade
go

alter table BusinessCardToCardFormat
   add constraint FK_BCARDFORM_REF_FORM foreign key (FormatCode)
      references CardFormat (FormatCode)
go

alter table FinishingPricePolicy
   add constraint FK_FINPRPOL_REF_FINSERV foreign key (FinishingServiceCode)
      references FinishingService (FinishingServiceCode)
go

alter table FinishingPricePolicy
   add constraint FK_FINPRPOL_REF_PRINTMED foreign key (PrintMediaCode)
      references PrintMedia (MediaCode)
go

alter table FinishingPricePolicy
   add constraint FK_FINPRPOL_REF_PRODTYP foreign key (ProductCode)
      references ProductType (ProductCode)
go

alter table FinishingService
   add constraint FK_FINSERV_REF_FINSERVTYP foreign key (FinishingServiceType)
      references FinishingServiceType (FinishingServiceType)
go

alter table Font
   add constraint FK_FONT_REF_LANGUAGE foreign key (LanguageCode)
      references Language (Code)
go

alter table NewsMessage
   add constraint FK_NEWSMESS_REF_LANG foreign key (LangCode)
      references Language (Code)
go

alter table "Order"
   add constraint FK_ORDER_REF_SHIPPING_ADR foreign key (ShippingAddressId)
      references ShippingAddress (ShippingAddressId)
go

alter table OrderHistory
   add constraint FK_ORDHIST_REF_ORDER foreign key (OrderId)
      references "Order" (OrderId)
go

alter table OrderHistory
   add constraint FK_ORDERHIS_REFERENCE_ASPNET_U foreign key (ModifierUserId)
      references aspnet_Users (UserId)
go

alter table Package
   add constraint FK_PACK_REF_ORDER foreign key (OrderId)
      references "Order" (OrderId)
go

alter table Package
   add constraint FK_PACK_REF_PRICEGRO foreign key (PricePolicyId)
      references PricePolicy (PricePolicyId)
go

alter table Package
   add constraint FK_PACK_REF_PRODUCT foreign key (ProductId)
      references Product (ProductId)
go

alter table Package
   add constraint FK_PACK_REF_PRTPRICPOL foreign key (PrintPricePolicyId)
      references PrintPricePolicy (PrintPricePolicyId)
go

alter table Package
   add constraint FK_PACKAGE_REFERENCE_BACKFACE foreign key (BackFaceId)
      references BackFace (BackFaceId)
go

alter table Package
   add constraint FK_PACKAGE_REFERENCE_ASPNET_U foreign key (UserId)
      references aspnet_Users (UserId)
go

alter table PackageToFinishingPricePolicy
   add constraint FK_PACKFINISH_REF_PACK foreign key (PackageId)
      references Package (PackageId)
go

alter table PackageToFinishingPricePolicy
   add constraint FK_PACKFINPRPOL_REF_FPRPOL foreign key (FinishingPricePolicyId)
      references FinishingPricePolicy (FinishingPricePolicyId)
go

alter table PrintMedia
   add constraint FK_PRINTMED_REF_PRINTMET foreign key (DefaultPrintMethodCode)
      references PrintMethod (MethodCode)
go

alter table PrintMedia
   add constraint FK_PRTMED_REF_PRTMEDTYP foreign key (MediaTypeCode)
      references PrintMediaType (MediaTypeCode)
go

alter table PrintMediaTypeToPrintMethod
   add constraint FK_PRMEDTMETH_REF_PRTMEDTY foreign key (MediaTypeCode)
      references PrintMediaType (MediaTypeCode)
go

alter table PrintMediaTypeToPrintMethod
   add constraint FK_PRTMEDTOMET_REF_PRTMET foreign key (MethodCode)
      references PrintMethod (MethodCode)
go

alter table PrintPricePolicy
   add constraint FK_PRPRICP_REF_PRINTMED foreign key (PrintMediaCode)
      references PrintMedia (MediaCode)
go

alter table PrintPricePolicy
   add constraint FK_PRPRICP_REF_PRINTMETH foreign key (PrintMethodCode)
      references PrintMethod (MethodCode)
go

alter table PrintPricePolicy
   add constraint FK_PRPRICP_REF_PRODTYP foreign key (ProductCode)
      references ProductType (ProductCode)
go

alter table Product
   add constraint FK_COMP_REF_PROD_TYP foreign key (ProductCode)
      references ProductType (ProductCode)
go

alter table Product
   add constraint FK_PROD_REF_BINDUSTRY foreign key (IndustryId)
      references Industry (IndustryId)
go

alter table Product
   add constraint FK_PROD_REF_BSTYLE foreign key (StyleId)
      references Style (StyleId)
go

alter table Product
   add constraint FK_PROD_REF_COLTHEME foreign key (ColorThemeId)
      references ColorTheme (ColorThemeId)
go

alter table Product
   add constraint FK_PROD_REF_DEF_DATATEMP foreign key (DefaultDataTemplateId)
      references DataTemplate (DataTemplateId)
go

alter table Product
   add constraint FK_PROD_REF_DESIGNGR foreign key (DesignGroupId)
      references DesignGroup (DesignGroupId)
go

alter table Product
   add constraint FK_PROD_REF_PRINTMED foreign key (DefaultPrintMedia)
      references PrintMedia (MediaCode)
go

alter table ProductToBackFace
   add constraint FK_BCARD_REF_BACKFACE foreign key (BackFaceId)
      references BackFace (BackFaceId)
go

alter table ProductToBackFace
   add constraint FK_PRODBACKFAC_REF_PROD foreign key (ProductId)
      references Product (ProductId)
go

alter table ProductToDataTemplate
   add constraint FK_BCDATMP_REF_CDATATMP foreign key (DataTemplateId)
      references DataTemplate (DataTemplateId)
go

alter table ProductToDataTemplate
   add constraint FK_PRDTTEMP_REF_PROD foreign key (ProductId)
      references Product (ProductId)
go

alter table ProductToPricePolicy
   add constraint FK_CMPPRG_REF_COMP foreign key (ProductId)
      references Product (ProductId)
go

alter table ProductToPricePolicy
   add constraint FK_CMP_REF_PRICEGRO foreign key (PricePolicyId)
      references PricePolicy (PricePolicyId)
go

alter table ProductToPrintMedia
   add constraint FK_PRODTOMED_REF_PROD foreign key (ProductId)
      references Product (ProductId)
         on delete cascade
go

alter table ProductToPrintMedia
   add constraint FK_PRODUCTT_REFERENCE_PRINTMED foreign key (MediaCode)
      references PrintMedia (MediaCode)
go

alter table TagToProduct
   add constraint FK_TAGTOCOM_REF_PROD foreign key (ProductId)
      references Product (ProductId)
         on delete cascade
go

alter table TagToProduct
   add constraint FK_TAGTOCOM_REF_TAG foreign key (TagId)
      references Tag (TagId)
go

